﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using MySql.Data.MySqlClient;
using System.Text;

namespace DA
{
    public class Logs : GO.BaseClass
    {
        public VO.Logs objVO;

        public Logs()
        {
            objVO = new VO.Logs();
            sbSQL = new StringBuilder();
        }

        public void Salvar()
        {
            // MONTA A INSTRUÇÃO SQL
            sbSQL.Append(" INSERT INTO `Logs` (Usuario, Acao, Data, Arquivo, idAcao, idUsuario) ");
            sbSQL.Append(" VALUES('p_Usuario','p_Acao','p_Arquivo','p_Data', p_idAcao,  p_idUsuario); ");

            // SUBSTITUI OS PARÂMETROS

            sbSQL.Replace("p_Usuario", objVO.Usuario);
            sbSQL.Replace("p_Acao", objVO.Acao);
            sbSQL.Replace("p_Arquivo", objVO.Arquivo);
            sbSQL.Replace("p_Data", objVO.Data.ToString("s"));
            sbSQL.Replace("p_idAcao", objVO.IdAcao.ToString());
            sbSQL.Replace("p_idUsuario", objVO.IdUsuario.ToString());

            // EXECUTA INSTRUÇÃO
            GO.MySQLHelper.ExecuteNonQuery(getConn(), sbSQL.ToString(), CommandType.Text);

            // LIMPA VARIÁVEL
            sbSQL.Remove(0, sbSQL.Length);
        }

        public void Atualizar()
        {
            // MONTA A INSTRUÇÃO SQL
            sbSQL.Append(" UPDATE `Logs` SET");
            sbSQL.Append("     Usuario  = 'p_Usuario ',");
            sbSQL.Append("     Acao  = 'p_Acao ',");
            sbSQL.Append("     Arquivo  = 'p_Arquivo ',");
            sbSQL.Append("     Data = 'p_Data' ");
            sbSQL.Append("     idAcao  = 'p_idAcao ',");
            sbSQL.Append("     idUsuario  = 'p_idUsuario ',");
            sbSQL.Append(" WHERE ");
            sbSQL.Append(" 	   idLog   = p_idLog  ;        ");

            // SUBSTITUI OS PARÂMETROS
            sbSQL.Replace("p_idLog", objVO.IdLog.ToString());
            sbSQL.Replace("p_Usuario", objVO.Usuario);
            sbSQL.Replace("p_Acao", objVO.Acao);
            sbSQL.Replace("p_Arquivo", objVO.Arquivo);
            sbSQL.Replace("p_Data", objVO.Data.ToString("s"));
            sbSQL.Replace("p_idAcao", objVO.IdAcao.ToString());
            sbSQL.Replace("p_idUsuario", objVO.IdUsuario.ToString());

            GO.MySQLHelper.ExecuteNonQuery(getConn(), sbSQL.ToString(), CommandType.Text);

            sbSQL.Remove(0, sbSQL.Length);
        }

        public void Excluir()
        {
            // Deleta Rota
            sbSQL.Append(" DELETE FROM `Logs` ");
            sbSQL.Append(" WHERE idLog   = p_idLog  ; ");

            // SUBSTITUI OS PARÂMETROS
            sbSQL.Replace("p_idLog", objVO.IdUsuario.ToString());

            GO.MySQLHelper.ExecuteNonQuery(getConn(), sbSQL.ToString(), CommandType.Text);
        }

        //public DataSet getTodosRegistros()
        //{

        //    //sbSQL.Append(" SELECT * FROM `Eventos`; ");

        //    //return GO.MySQLHelper.ExecuteDataset(getConn(), sbSQL.ToString(), CommandType.Text);
        //}

        //public DataSet getRegistroById()
        //{
        //    //sbSQL.Append(" SELECT * FROM `Eventos` ");
        //    //sbSQL.Append(" WHERE idEvento = p_idEvento; ");
        //    //sbSQL.Replace("p_idEvento", objVO.IdEvento.ToString());

        //    //return GO.MySQLHelper.ExecuteDataset(getConn(), sbSQL.ToString(), CommandType.Text);
        //}
    }
}